package com.bestcem.xm.ticket.entity.mongo;

import com.bestcem.xm.ticket.constant.ColumnConstant;
import com.bestcem.xm.ticket.enums.TicketRecordEventEnum;
import com.bestcem.xm.ticket.enums.TicketRecordSourceEnum;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 记录工单的各个进度
 * 一个工单对应多条记录
 *
 * @author XiaoYunSong <ys.xiao@idiaoyan.com>
 * @version v1.0
 * @date 2021/8/10 16:13
 */
@ToString(callSuper = true)
@Getter
@Setter
public class TicketRecord extends BaseEntity {

    private static final long serialVersionUID = -7253778583948098509L;

    /**
     * 工单所属租户id
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.ORG_ID)
    private String orgId;

    /**
     * 操作人id
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.USER_ID)
    private String userId;

    /**
     * 日志标题
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.TITLE)
    private String title;

    /**
     * 工单id
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.TICKET_ID)
    private String ticketId;

    /**
     * 接受转派的角色id
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.ROLE_ID)
    private String roleId;

    /**
     * 接受转派的层级id
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.REGION)
    private String region;

    /**
     * 接受转派的层级名称
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.REGION_NAME)
    private String regionName;

    /**
     * 操作人姓名
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.USER_NAME)
    private String userName;

    /**
     * 操作类型
     *
     * @see TicketRecordSourceEnum
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.SOURCE)
    private Integer source;

    /**
     * 工单事件
     *
     * @see TicketRecordEventEnum
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.EVENT)
    private Integer event;

    /**
     * 处理模板定义字段
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.CUSTOM_ATTR)
    private CustomAttr customAttr;

    /**
     * 问卷id
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.SURVEY_ID)
    private String surveyId;

    /**
     * 工单状态
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.TICKET_STATUS)
    private Integer ticketStatus;

    /**
     * 原因。
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.REASON)
    private String reason;

    /**
     * 是否sample
     */
    @JsonProperty(value = ColumnConstant.TicketRecord.SAMPLE)
    private Boolean sample;

    /**
     * 接受转派的用户id
     */
    private String receiveUserId;

    /**
     * 接受转派的用户名字
     */
    private String receiveUserName;


    /**
     * 接受转派的角色id
     */
    private String receiveRoleId;

    /**
     * 接受转派的角色名
     */
    private String receiveRoleName;

    /**
     * 接受转派的层级名
     */
    private String receiveRegionName;

    /**
     * 接受转派的层级id
     */
    private String receiveRegionId;


    /**
     * 工单进度自定义参数, 分为两种 跟进/审核
     *
     * @author XiaoYunSong <ys.xiao@idiaoyan.com>
     * @date 2021/8/18 15:35
     */
    @NoArgsConstructor
    @ToString(callSuper = true)
    @Getter
    @Setter
    public static class CustomAttr implements Serializable {
        private static final long serialVersionUID = 2808726620840986656L;

        // ==== 公共参数 ====
        /**
         * content
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.CONTENT)
        private String content;

        // ==== 跟进参数 ====
        /**
         * isCompleted
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.IS_COMPLETED)
        private Boolean isCompleted;

        /**
         * custom_fields
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.CUSTOM_FIELDS)
        private List<CustomField> customFields;

        @NoArgsConstructor
        @AllArgsConstructor
        @Data
        public static class CustomField implements Serializable {
            private static final long serialVersionUID = 2808726620840986656L;

            /**
             * field
             */
            private String field;

            /**
             * text
             */
            private String text;

            /**
             * value
             */
            private String value;
        }

        // ==== 审核参数 ====
        /**
         * isAgreed
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.IS_AGREED)
        private Boolean isAgreed;

        /**
         * auditHandle
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.AUDIT_HANDLE)
        private Integer auditHandle;

        /**
         * timeLimit
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.TIME_LIMIT)
        private Integer timeLimit;

        /**
         * timeLimitType
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.TIME_LIMIT_TYPE)
        private Integer timeLimitType;

        /**
         * transferFollowDeadline
         */
        @JsonProperty(value = ColumnConstant.TicketRecord.CustomAttr.TRANSFER_FOLLOW_DEADLINE)
        private Date transferFollowDeadline;
    }
}
